<!--
这是一个来自github的示例
-->
<script>

var t0, t1;

t0 = performance.now();
const mediaSource = new MediaSource();
t1 = performance.now();
log(t0, t1, 'new MediaSource');
video.src = URL.createObjectURL(mediaSource);

t0 = performance.now();
mediaSource.addEventListener('sourceopen', async function() {
  t1 = performance.now();
  log(t0, t1, 'sourceopen     ');
  URL.revokeObjectURL(video.src);

  t0 = performance.now();
  const sourceBuffer = mediaSource.addSourceBuffer('video/mp4;codecs="avc1.4D4001,mp4a.40.2"');
  t1 = performance.now();
  log(t0, t1, 'addSourceBuffer');
  
  const writable = new WritableStream({
    write(chunk) {
      return new Promise(resolve => {
        t0 = performance.now();
        sourceBuffer.appendBuffer(chunk);
        sourceBuffer.addEventListener('updateend', () => {
          t1 = performance.now();
          log(t0, t1, 'appendBuffer   ');
          resolve();
        }, { once: true });
      })
    },
    close() {
      mediaSource.endOfStream();
    }
  });
  
  const response = await fetch('https://storage.googleapis.com/media-session/bear-1280x720-av_frag.mp4');
  response.body.pipeTo(writable);
});




</script>